import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import './common/video/video_player_UI.dart';

class ShowVideo extends StatefulWidget {

  static final String sName = "resource";

  final String resourceUrl;
  final String resourceName;

  ShowVideo(this.resourceName, this.resourceUrl,{Key key}) : super(key: key);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _VideoAppState(resourceName,resourceUrl);
  }
}

class _VideoAppState extends State<ShowVideo> {

  final String resourceName;
  final String resourceUrl;

  _VideoAppState(this.resourceName,this.resourceUrl);
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(resourceUrl)
      ..initialize().then((_) {
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        // 该组件宽高默认填充父控件，你也可以自己设置宽高
        child: VideoPlayerUI.network(
          url:
          resourceUrl,
          title:resourceName,
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }
}